﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Portal.Xml.Utility;

namespace Portal.Cms.Model
{
    public class NewsLevelCls
    {
        public string NewsLevelId;
        public string NewsLevelName;
        public int SortIndex = 0;
    }

    public class NewsLevelParser
    {
        public static NewsLevelCls CreateInstance()
        {
            //tao 1 class trang....
            NewsLevelCls oNewsLevelCls = new NewsLevelCls();
            return oNewsLevelCls;
        }

        public static NewsLevelCls ParseFromXml(string XmlData)
        {
            DataSet ds = XmlUtility.GetDataSetFromXml(XmlData);
            NewsLevelCls oNewsLevelCls = ParseFromDataRow(ds.Tables[0].Rows[0]);
            return oNewsLevelCls;
        }


        public static NewsLevelCls ParseFromDataRow(DataRow dr)
        {
            NewsLevelCls oNewsLevelCls = new NewsLevelCls();
            oNewsLevelCls.NewsLevelId = XmlUtility.GetString(dr, "NewsLevelId", true);
            oNewsLevelCls.NewsLevelName = XmlUtility.GetString(dr, "NewsLevelName", true);
            oNewsLevelCls.SortIndex = XmlUtility.GetInt(dr, "SortIndex", true);
            return oNewsLevelCls;
        }

        public static NewsLevelCls[] ParseFromDataTable(DataTable dtTable)
        {
            NewsLevelCls[] NewsLevels = new NewsLevelCls[dtTable.Rows.Count];
            for (int iIndex = 0; iIndex < dtTable.Rows.Count; iIndex++)
            {
                NewsLevels[iIndex] = ParseFromDataRow(dtTable.Rows[iIndex]);
            }

            return NewsLevels;
        }




        public static NewsLevelCls[] ParseMultiRecordFromXml(string XmlData)
        {
            DataSet ds = XmlUtility.GetDataSetFromXml(XmlData);
            if (ds.Tables.Count == 0)
            {
                return new NewsLevelCls[0];
            }
            NewsLevelCls[] NewsLevels = new NewsLevelCls[ds.Tables[0].Rows.Count];
            for (int iIndex = 0; iIndex < ds.Tables[0].Rows.Count; iIndex++)
            {
                NewsLevels[iIndex] = ParseFromDataRow(ds.Tables[0].Rows[iIndex]);
            }
            return NewsLevels;
        }
    }
}
